using System;
using UnityEngine;
using UnityEngine.Networking;

namespace Voodoo.Sauce.Internal.GDPR
{
	public static class VoodooGDPRAPI
	{
		private const string BaseUrl = "https://api-gdpr.voodoo-tech.io/";

		public static void NeedConsent(NeedConsentParams data, Action<NeedConsent> onSuccess, Action onError)
		{
			string url = "https://api-gdpr.voodoo-tech.io/need_consent" + data;
			Requests.Get(url, null, delegate(UnityWebRequest request)
			{
				NeedConsent obj = JsonUtility.FromJson<NeedConsent>(request.downloadHandler.text);
				if (onSuccess != null)
				{
					onSuccess(obj);
				}
			}, delegate
			{
				if (onError != null)
				{
					onError();
				}
			});
		}

		public static void ConsentInsights(ConsentInsightsParams data, Action onSuccess = null, Action onError = null)
		{
			string url = "https://api-gdpr.voodoo-tech.io/consent_insights" + data;
			Requests.Get(url, null, delegate
			{
				if (onSuccess != null)
				{
					onSuccess();
				}
			}, delegate
			{
				if (onError != null)
				{
					onError();
				}
			});
		}

		public static void PrivacyRequest(PrivacyRequestParams data, Action<PrivacyRequest> onSuccess = null, Action<PrivacyRequest> onError = null)
		{
			string url = "https://api-gdpr.voodoo-tech.io/privacy_request";
			Requests.PostJson(url, JsonUtility.ToJson(data), null, delegate(UnityWebRequest request)
			{
				PrivacyRequest obj2 = JsonUtility.FromJson<PrivacyRequest>(request.downloadHandler.text);
				if (onSuccess != null)
				{
					onSuccess(obj2);
				}
			}, delegate(UnityWebRequest request)
			{
				PrivacyRequest obj = null;
				try
				{
					obj = JsonUtility.FromJson<PrivacyRequest>(request.downloadHandler.text);
				}
				catch (Exception)
				{
				}
				if (onError != null)
				{
					onError(obj);
				}
			});
		}
	}
}
